package ace.module.tenant.core.autoconfig;

import ace.cmp.jetcache.anno.config.EnableAceMethodCache;
import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslJdbcRepositoryExtendFactoryBean;
import ace.module.tenant.core.impl.TenantCoreBootstrapScanner;
import ace.module.tenant.core.impl.dao.repository.RepositoryScanner;
import ace.module.tenant.core.impl.properties.TenantCoreProperties;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.*;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.stereotype.Repository;

/**
 * boostrap auto config.
 *
 * @author Caspar
 */
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableAceMethodCache(basePackageClasses = {TenantCoreBootstrapScanner.class})
@EnableConfigurationProperties({TenantCoreProperties.class})
@EnableJdbcRepositories(
    basePackageClasses = {RepositoryScanner.class},
    repositoryFactoryBeanClass = QuerydslJdbcRepositoryExtendFactoryBean.class)
@ComponentScan(
    basePackageClasses = TenantCoreBootstrapScanner.class,
    excludeFilters = {
      @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Repository.class)
    })
@Configuration
public class TenantCoreAutoConfig {
  @Bean
  public GroupedOpenApi tenantGroupedOpenApi() {
    return GroupedOpenApi.builder()
        .group("tenant")
        .displayName("租户服务")
        .packagesToScan(TenantCoreBootstrapScanner.class.getPackageName())
        .build();
  }
}
